package main

import (
	"fmt"
	"log"
	"net"
	"os"

	"github.com/urfave/cli"
)

func main() {

	app := cli.NewApp()

	app.Commands = []cli.Command{
		{
			Name:  "ns",
			Usage: "Looks Up the NameServers for a Particular Host",
			Action: func(c *cli.Context) error {
				host := c.Args().First()
				ns, err := net.LookupNS(host)
				if err != nil {
					log.Fatal(err)
				}
				for _, n := range ns {
					fmt.Println(n.Host)
				}
				return nil
			},
		},
		{
			Name:  "cname",
			Usage: "Looks up the CNAME for a particular host",
			Action: func(c *cli.Context) error {
				host := c.Args().First()
				cname, err := net.LookupCNAME(host)
				fmt.Println(cname)
				if err != nil {
					log.Fatal(err)
				}
				return nil
			},
		},
		{
			Name:  "ip",
			Usage: "Looks up the IP addresses for a particular host",
			Action: func(c *cli.Context) error {
				host := c.Args().First()
				ip, err := net.LookupIP(host)
				if err != nil {
					log.Fatal(err)
				}
				fmt.Println(ip)
				return nil
			},
		},
	}
	err := app.Run(os.Args)
	if err != nil {
		log.Fatal(err)
	}

}
